home *** CD-ROM | disk | FTP | other *** search
/ Alles Voor Internet / Tout Pour Internet / alles voor internet.iso / MacInternet™ / Telnet / NCSA / tn3270 2.4d7 source / tn3270 / crcf.c < prev    next >
Text File  |  1992-04-17  |  3KB  |  91 lines

  1. /*
  2.  *  tn3270 for the Macintosh Source Code
  3.  *  Brown University Computing and Information Services
  4.  *  Version 2.4d7  April, 1992
  5.  *  Copyright (c) 1988, 1989, 1990, 1991, 1992 by Brown University and by
  6.  *  Peter John DiCamillo.
  7.  *
  8.  *  Permission is granted to any individual or institution to use, copy,
  9.  *  or redistribute the binary version of this software and its
  10.  *  documentation provided this notice and the copyright notices are
  11.  *  retained.  Permission is granted to any individual or non-profit
  12.  *  institution to use, copy, modify, or redistribute the source files
  13.  *  of this software provided this notice and the copyright notices are
  14.  *  retained.  This software may not be distributed for profit, either
  15.  *  in original form or in derivative works, nor can the source be
  16.  *  distributed to other than an individual or a non-profit institution.
  17.  *  Any  individual or group interested in seeing and/or using these
  18.  *  source files but who are prevented from doing so by the above
  19.  *  constraints should contact Don Wolfe, Assistant Vice-President for
  20.  *  Computer Systems at Brown University, (401) 863-7250, for possible
  21.  *  software licensing of the source developed at Brown.
  22.  *
  23.  *  Brown University and Peter John DiCamillo make no representations
  24.  *  about the suitability of this software for any purpose.
  25.  *
  26.  *  BROWN UNIVERSITY AND PETER JOHN DICAMILLO GIVE NO WARRANTY, EITHER
  27.  *  EXPRESS OR IMPLIED, FOR THE PROGRAM AND/OR DOCUMENTATION PROVIDED,
  28.  *  INCLUDING, WITHOUT LIMITATION, WARRANTY OF MERCHANTABILITY AND
  29.  *  WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE.
  30.  *
  31.  */
  32.  
  33. #pragma segment vmxfer
  34.  
  35. /* from tn3270funcs.h */
  36. int crcf(unsigned char *str, short len, unsigned short initchk);
  37. void gentab(unsigned short *array);
  38.  
  39. int crcf(unsigned char *str, short len, unsigned short initchk)
  40. {
  41. static char tabok = 0;
  42. static unsigned short crctab[256];
  43. register short i, table_pos;
  44. register unsigned short result;
  45.  
  46. if (!tabok) {
  47.     gentab(crctab);
  48.     tabok = 1;
  49.     }
  50.  
  51. result = initchk;
  52. for (i=0; i < len; i++) {
  53.     table_pos = (result ^ str[i]) & 0x00ff;
  54.     result >>= 8;
  55.     result ^= crctab[table_pos];
  56.     }
  57.  
  58. return(result);
  59. }
  60.  
  61. void gentab(unsigned short *array)
  62. {
  63. char x, x1, x2, x3, x4, x5, x6, x7, x8;
  64. register short count;
  65.  
  66. count = 0;
  67.  
  68. for (x8=0; x8 < 2; x8++)
  69.  for (x7=0; x7 < 2; x7++)
  70.   for (x6=0; x6 < 2; x6++)
  71.    for (x5=0; x5 < 2; x5++)
  72.     for (x4=0; x4 < 2; x4++)
  73.      for (x3=0; x3 < 2; x3++)
  74.       for (x2=0; x2 < 2; x2++)
  75.        for (x1=0; x1 < 2; x1++) {
  76.         array[count] = 0;
  77.         x = x8 ^ x7 ^ x6 ^ x5 ^ x4 ^ x3 ^ x2 ^ x1;
  78.         if (x) array[count] += 0x8000;
  79.         if (x7 ^ x6 ^ x5 ^ x4 ^ x3 ^ x2 ^ x1) array[count] += 0x4000;
  80.         if (x8 ^ x7) array[count] += 0x2000;
  81.         if (x7 ^ x6) array[count] += 0x1000;
  82.         if (x6 ^ x5) array[count] += 0x0800;
  83.         if (x5 ^ x4) array[count] += 0x0400;
  84.         if (x4 ^ x3) array[count] += 0x0200;
  85.         if (x3 ^ x2) array[count] += 0x0100;
  86.         if (x2 ^ x1) array[count] += 0x0080;
  87.         if (x1) array[count] += 0x0040;
  88.         array[count++] += x;
  89.         }
  90. }
  91.